package extra.navigator;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JWindow;
import javax.swing.UIManager;

import extra.navigator.JGroupPanel.GroupLayout;
import extra.navigator.JGroupPanel.JGroupContainer;


public class ExtraNavigatorUI_1 extends JFrame {
	public static ExtraNavigatorData mainData;
	Dimension dim;
	public ExtraNavigatorUI_1(ExtraNavigatorData mainData) {
		// TODO Auto-generated constructor stub
		this.mainData = mainData;
		dim =Toolkit.getDefaultToolkit().getScreenSize();
	}
	public void run() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
		this.setTitle("Extra NAV");
		//Set the Position;
		int Xpos = (dim.width - 500) / 2; 
		int Ypos = (dim.height - 400) / 2; 
		this.setBounds(Xpos, Ypos, 500, 400); 
//		this.setAlwaysOnTop(true);
	
 
		
		
		JPanel InputPanel = new JPanel();
		JTextField TextInput = new JTextField();
		JButton Button = new JButton();
		TextInput.setText("Inlput");
		TextInput.setBounds(0, 0, 20, 200);
		Button.setText("Search");
		
		// this Button is for AddFile to the NAV Database;
		JButton ButtonAddNewFile = new JButton();
		ButtonAddNewFile.setText("Add File & Dir");
		ButtonAddNewFile.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				AddFileUI NewAddFileFrame = new AddFileUI();
				NewAddFileFrame.run();
			}
			
		});
		
		InputPanel.add(TextInput);
		InputPanel.add(Button);
		InputPanel.add(ButtonAddNewFile);
	
		InputPanel.setBounds(0, 280, 350, 30); 
		InputPanel.setLayout(new FlowLayout());
		this.add(InputPanel);

		//Add Tag Pandl
		JPanel TagPanel = new JPanel();
		int NumberOfTag = mainData.Tags.size();
		for (int i = 0; i<NumberOfTag; i++ ) {
			TagLabel xxx = new TagLabel(mainData.Tags.get(i).TagName);
			TagPanel.add(xxx);
		}
		TagPanel.setBounds(0, 310, 500, 90); 
		TagPanel.setLayout(new FlowLayout());
		this.add(TagPanel);
		
		
		//Add Extra Pandl
	
		JGroupPanel ExtraPanel = new JGroupPanel();
		ExtraPanel.setBounds(350, 0, 140, 310); 
		
		ExtraPanel.insertGroup(0, "Recent Used");
		ExtraPanel.insertGroup(1, "Tag Indexing");
		ExtraPanel.insertGroup(2, "File Search");
		ExtraPanel.expandGroup(0);
		
        JButton bttMember = new JButton("XXX");
        bttMember.setActionCommand("XXX");
        bttMember.setPreferredSize(new Dimension(1, 40));
        JButton bttMember2 = new JButton("XXX");
        bttMember2.setActionCommand("XXX");
        bttMember2.setPreferredSize(new Dimension(1, 40));
        JButton bttMember3 = new JButton("XXX");
        bttMember3.setActionCommand("XXX");
        bttMember3.setPreferredSize(new Dimension(1, 40));
        JButton bttMember4 = new JButton("XXX");
        bttMember4.setActionCommand("XXX");
        bttMember4.setPreferredSize(new Dimension(1, 40));
        JButton bttMember5 = new JButton("XXX");
        bttMember5.setActionCommand("XXX");
        bttMember5.setPreferredSize(new Dimension(1, 40));
        JButton bttMember6 = new JButton("XXX");
        bttMember6.setActionCommand("XXX");
        bttMember6.setPreferredSize(new Dimension(1, 40));

        JLabel lb = new JLabel("XXX");
        JLabel lb2 = new JLabel("XXX");
        JLabel lb3 = new JLabel("XXX");
        JLabel lb4 = new JLabel("XXX");
        ExtraPanel.addMember(0, bttMember);
        ExtraPanel.addMember(0, bttMember2);
        ExtraPanel.addMember(0, bttMember3);
        ExtraPanel.addMember(0, bttMember4);
        ExtraPanel.addMember(0, bttMember5);
        ExtraPanel.addMember(0, bttMember6);
		
		this.getContentPane().add(ExtraPanel, BorderLayout.CENTER);
	

		//Add File Data Panel
		JPanel FilePanel = new JPanel();

		
		JTabbedPane jTabbedPaneFiles = new JTabbedPane();
		JPanel jTabbedPane0 = new JPanel();
		JPanel jTabbedPane1 = new JPanel();
		JPanel jTabbedPane2 = new JPanel();
		JPanel jTabbedPane3 = new JPanel();
		JPanel jTabbedPane4 = new JPanel();
		JPanel jTabbedPane5 = new JPanel();
		JPanel jTabbedPane9 = new JPanel();

		jTabbedPaneFiles.addTab("DIR", jTabbedPane0);
		jTabbedPaneFiles.addTab("EXE", jTabbedPane1);
		jTabbedPaneFiles.addTab("TXT", jTabbedPane2);
		jTabbedPaneFiles.addTab("MUSIC", jTabbedPane3);
		jTabbedPaneFiles.addTab("PIC", jTabbedPane4);
		jTabbedPaneFiles.addTab("WEB", jTabbedPane5);
		jTabbedPaneFiles.addTab("OTHERS", jTabbedPane9);
		
		int NumberOfFile = mainData.Files.size();
		for (int i=0; i<NumberOfFile; i++ ) {
			int FileType =  mainData.Files.get(i).FileType;
			FileLabel xxx = new FileLabel(mainData.Files.get(i));
			System.out.println("GOT");
			switch (FileType) {
			case 0:
				jTabbedPane0.add(xxx);
				break;
			case 1:
				jTabbedPane1.add(xxx);
				break;
			case 2:
				jTabbedPane2.add(xxx);
				break;
			case 3:
				jTabbedPane3.add(xxx);
				break;
			case 4:
				jTabbedPane4.add(xxx);
				break;
			case 5:
				jTabbedPane5.add(xxx);
				break;
			default:
				jTabbedPane9.add(xxx);
				break;
			}
		}
		
		jTabbedPaneFiles.setBounds(0, 0, 350, 280); 
		jTabbedPaneFiles.setVisible(true);
		
		FilePanel.add(jTabbedPaneFiles);
		FilePanel.setBounds(0, 0, 350, 280); 
		FilePanel.setLayout(null);
		this.add(FilePanel);

		com.sun.awt.AWTUtilities.setWindowOpacity(this, 1f);
		this.setVisible(true); 
		
	}
}

class TagLabel extends JLabel implements MouseListener  {
	String LabelText;
	public TagLabel(String text) {
		// TODO Auto-generated method stub
		this.LabelText = text;
		this.setText(text);
		this.addMouseListener(this);
		Font mf = new Font("新宋体",Font.PLAIN, 12);
		this.setFont(mf);
		this.setBackground(Color.RED);   
	}

	public void mousePressed(MouseEvent e) {
	}
	public void mouseReleased(MouseEvent e){
	}
	public void mouseEntered(MouseEvent e) {
	}
	public void mouseExited(MouseEvent e) {
	}
	public void mouseClicked(MouseEvent e) {
		System.out.println(LabelText);
	}
}

class FileLabel extends JLabel implements MouseListener  {
	FileData MyFile;
	public FileLabel(FileData newMyFile) {
		// TODO Auto-generated method stub
		MyFile = newMyFile;
		this.setText(MyFile.FileName);
		this.addMouseListener(this);
		Font mf = new Font("新宋体",Font.PLAIN, 16);
		this.setFont(mf);
	}

	public void mousePressed(MouseEvent e) {
	}
	public void mouseReleased(MouseEvent e){
	}
	public void mouseEntered(MouseEvent e) {
	}
	public void mouseExited(MouseEvent e) {
	}
	public void mouseClicked(MouseEvent e) {
		ExtraNavigatorEventNav.Navigate(MyFile.Position , MyFile.FileType);
		ExtraNavigatorUI_1.mainData.visited(MyFile);
	}
}


class ExtraPanel extends JPanel {
	ExtraNavigatorData mainData;
	public ExtraPanel(ExtraNavigatorData mainData) {
		// TODO Auto-generated method stub
		this.mainData = mainData;
	}
	
	public void ShowRecent (int Number) {
		if (Number<=0) Number = 10;
	}
	
	public void ShowTag (String Tag) {
	
	}
}


class JGroupPanel extends JPanel {
    /* 锟斤拷4锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 */
    private JPanel pNorth = new JPanel() {
    };

    private JPanel pCenter = new JPanel();

    private JPanel pSouth = new JPanel();

    int[] openFlag = new int[3];

    /* 锟斤拷前全锟斤拷锟斤拷募锟斤拷锟�*/
    private ArrayList groupList = new ArrayList();

    /* 锟角凤拷锟窖斤拷止锟斤拷锟斤拷锟斤拷 */
    private boolean forbidFlag = false;

    String[][] str = new String[3][5];

    /* 锟斤拷前锟斤拷锟斤拷锟斤拷锟�*/
    private JGroupContainer activeGroup = null;

    transient ActionListener al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            JButton bttTitle = (JButton) e.getSource();
            expandGroup((JGroupContainer) bttTitle.getParent());
        }
    };

    public boolean hasCreateDefaultGroup = false;

    public JGroupPanel() {
        initComponents();
    }

    private void initComponents() {
        this.setLayout(new BorderLayout());
        this.add(pNorth, BorderLayout.NORTH);
        this.add(pCenter, BorderLayout.CENTER);
        this.add(pSouth, BorderLayout.SOUTH);
        pNorth.setLayout(new GroupLayout());
        pCenter.setLayout(new BorderLayout());
        pSouth.setLayout(new GroupLayout());
        forbidFlag = true;
        for (int i = 0; i < 3; i++) {
            openFlag[i] = 0;
        }
    }

    /**
     * @param groupNames
     *            String[] 预锟斤拷锟斤拷锟斤拷
     */
    public JGroupPanel(String groupNames[]) {
        initComponents();
        addGroup(groupNames);
    }

    /**
     * 展锟斤拷锟斤拷
     *
     * @param name
     *            String 锟斤拷锟斤拷
     */
    public void expandGroup(String name) {
        for (int i = getGroupCount() - 1; i >= 0; i--) {
            if (getGroupName(i).equals(name)) {
                expandGroup(i);
            }
        }
    }

    /**
     * 展锟斤拷锟斤拷
     *
     * @param index
     *            int 锟斤拷锟剿筹拷锟斤拷
     */
    public void expandGroup(int index) {
        expandGroup(getGroup(index));
    }

    /**
     * 展锟斤拷锟斤拷
     *
     * @param group
     *            JGroupContainer 锟斤拷
     */
    protected void expandGroup(JGroupContainer group) {
        int num = 0;
        pNorth.removeAll();
        pCenter.removeAll();
        pSouth.removeAll();
        boolean hasAddCenter = false;
        for (int i = 0; i < groupList.size(); i++) {
            Component c = (Component) groupList.get(i);
            if (openFlag[i] == 0) {
                if (hasAddCenter) {
                    pSouth.add(c);
                } else if (c == group) {
                    pCenter.add(c, BorderLayout.CENTER);
                    openFlag[i] = 1;
                    num = i + 1;
                    hasAddCenter = true;
                } else {
                    pNorth.add(c);
                }
            } else {
                if (activeGroup != null) {
                    activeGroup.collapse();
                    activeGroup = null;
                }
                if (c == group) {
                    pNorth.add(c);
                } else if (num == 0) {
                    pNorth.add(c);
                } else if (num > i + 1) {
                    pNorth.add(c);
                } else {
                    pSouth.add(c);
                }

                openFlag[i] = 0;
            }
        }
        if (activeGroup != null) {
            activeGroup.collapse();
        }
        for (int i = 0; i < groupList.size(); i++) {
            Component c = (Component) groupList.get(i);
            if (c == group && openFlag[i] == 1) {
                activeGroup = group;
                activeGroup.expand();
            }
        }
        pNorth.doLayout();
        pCenter.doLayout();
        pSouth.doLayout();
        doLayout();
    }

    /**
     * 锟斤拷锟斤拷锟斤拷
     *
     * @param name
     *            String 锟斤拷锟斤拷
     */
    public void collapseGroup(String name) {
        for (int i = getGroupCount() - 1; i >= 0; i--) {
            if (getGroupName(i).equals(name)) {
                collapseGroup(i);
            }
        }
    }

    /**
     * 锟斤拷锟斤拷锟斤拷
     *
     * @param index
     *            int 锟斤拷锟剿筹拷锟斤拷
     */
    public void collapseGroup(int index) {
        collapseGroup(getGroup(index));
    }

    /**
     * 锟斤拷锟斤拷锟斤拷
     *
     * @param group
     *            JGroupContainer 锟斤拷
     */
    protected void collapseGroup(JGroupContainer group) {
        if (group == activeGroup) {
            activeGroup.collapse();
            activeGroup = null;
        }
    }

    /**
     * 锟斤拷锟斤拷锟�
     *
     * @param name
     *            String 锟斤拷锟斤拷
     */
    public void addGroup(String name) {
        this.insertGroup(getGroupCount(), name);
    }

    /**
     * 锟斤拷佣锟斤拷锟斤拷
     *
     * @param names
     *            String[] 锟斤拷锟斤拷
     */
    public void addGroup(String names[]) {
        for (int i = 0; i < names.length; i++) {
            addGroup(names[i]);
        }
    }

    /**
     * 锟斤拷锟斤拷一锟斤拷锟斤拷
     *
     * @param index
     *            int 顺锟斤拷锟�
     * @param name
     *            String 锟斤拷锟斤拷
     * @param bg
     *            Color 锟斤拷锟斤拷色
     */
    public void insertGroup(int index, String name, Color bg) {
        if (index < 0 || index > groupList.size()) {
            throw new ArrayIndexOutOfBoundsException("index:" + index
                    + " >count:" + groupList.size());
        }
        if (hasCreateDefaultGroup) {
            while (getGroupCount() > 0) {
                removeGroup(0);
            }
            hasCreateDefaultGroup = false;
        }
        int countNorth = pNorth.getComponentCount();
        int countCenter = pCenter.getComponentCount();
        int countSouth = pSouth.getComponentCount();
        JGroupContainer group;
        if (index <= countNorth) {
            group = insertGroup(pNorth, index, name, bg);
        } else if (index <= countNorth + countCenter) {
            group = insertGroup(pCenter, index - countNorth, name, bg);
        } else if (index <= countNorth + countCenter + countSouth) {
            group = insertGroup(pSouth, index - countNorth - countCenter, name,
                    bg);
        } else {
            group = insertGroup(pSouth, countSouth, name, bg);
        }
        group.getTitleButton().addActionListener(al);
        groupList.add(index, group);

    }

    /**
     * 锟斤拷锟斤拷一锟斤拷锟斤拷
     *
     * @param index
     *            int 顺锟斤拷锟�
     * @param name
     *            String 锟斤拷锟斤拷
     */
    public void insertGroup(int index, String name) {
        insertGroup(index, name, UIManager.getColor("Desktop.background"));
    }

    /**
     * 锟斤拷锟斤拷一锟斤拷锟斤拷
     *
     * @param p
     *            JPanel 目锟斤拷锟斤拷锟�
     * @param index
     *            int 顺锟斤拷锟�
     * @param name
     *            String 锟斤拷锟斤拷
     *
     *
     * /** 锟斤拷锟斤拷一锟斤拷锟斤拷
     * @param p
     *            JPanel 目锟斤拷锟斤拷锟�
     * @param index
     *            int 顺锟斤拷锟�
     * @param name
     *            String 锟斤拷锟斤拷
     * @return JGroupContainer
     */
    private JGroupContainer insertGroup(JPanel p, int index, String name,
            Color bg) {
        JGroupContainer group = new JGroupContainer(name, bg);
        p.add(group);
        return group;
    }

    /**
     * 删锟斤拷一锟斤拷锟斤拷
     *
     * @param index
     *            int 顺锟斤拷锟�
     */
    public void removeGroup(int index) {
        JGroupContainer c = (JGroupContainer) groupList.get(index);
        c.getParent().remove(c);
        c.getTitleButton().removeActionListener(al);
    }

    /**
     * 删锟斤拷一锟斤拷锟斤拷
     *
     * @param name
     *            String 锟斤拷锟斤拷
     */
    public void removeGroup(String name) {
        for (int i = getGroupCount() - 1; i >= 0; i--) {
            if (getGroupName(i).equals(name)) {
                this.removeGroup(i);
            }
        }
    }

    /**
     * 锟斤拷锟斤拷锟斤拷锟斤拷
     *
     * @param index
     *            int 顺锟斤拷锟�
     * @param name
     *            String 锟斤拷锟斤拷
     */
    public void setGroupName(int index, String name) {
        this.getGroup(index).setName(name);
    }

    /**
     * 取锟斤拷锟斤拷锟斤拷
     *
     * @param groupIndex
     *            int 顺锟斤拷锟�
     * @return String 锟斤拷锟斤拷
     */
    public String getGroupName(int groupIndex) {
        return getGroup(groupIndex).getName();
    }

    /**
     * 取锟斤拷全锟斤拷锟斤拷锟斤拷
     *
     * @return String[]
     */
    public String[] getGroupNames() {
        String sResult[] = new String[getGroupCount()];
        for (int i = 0; i < getGroupCount(); i++) {
            sResult[i] = getGroupName(i);
        }
        return sResult;
    }

    /**
     * 取锟矫碉拷前锟斤拷锟斤拷锟斤拷锟�
     *
     * @return int
     */
    public int getGroupCount() {
        return groupList.size();
    }

    /**
     * 锟斤拷锟斤拷锟斤拷锟斤拷映锟皆憋拷锟斤拷
     *
     * @param groupIndex
     *            int 锟斤拷锟剿筹拷锟斤拷
     * @param member
     *            Component 锟斤拷员锟斤拷锟�
     */
    public void addMember(int groupIndex, Component member) {
        getGroup(groupIndex).addMember(getGroup(groupIndex).getMemberCount(),
                member);
    }

    /**
     * 锟斤拷锟斤拷锟叫诧拷锟斤拷锟皆憋拷锟斤拷
     *
     * @param groupIndex
     *            int 锟斤拷锟剿筹拷锟斤拷
     * @param memberIndex
     *            int 锟斤拷锟斤拷锟剿筹拷锟斤拷
     * @param member
     *            Component 锟斤拷员锟斤拷锟�
     */
    public void insertMember(int groupIndex, int memberIndex, Component member) {
        getGroup(groupIndex).addMember(memberIndex, member);
    }

    /**
     * 锟斤拷锟斤拷锟斤拷锟狡筹拷锟皆憋拷锟斤拷
     *
     * @param groupIndex
     *            int
     * @param memberIndex
     *            int
     */
    public void removeMember(int groupIndex, int memberIndex) {
        getGroup(groupIndex).removeMember(memberIndex);
    }

    /**
     * 取锟矫筹拷员锟斤拷锟�
     *
     * @param groupIndex
     *            int 锟斤拷锟剿筹拷锟斤拷
     * @param memberIndex
     *            int 锟斤拷员锟斤拷锟斤拷锟剿筹拷锟斤拷
     * @return Component 锟斤拷员锟斤拷锟�
     */
    public Component getMember(int groupIndex, int memberIndex) {
        return getGroup(groupIndex).getMember(memberIndex);
    }

    /**
     * 取锟斤拷全锟斤拷锟斤拷员锟斤拷锟�
     *
     * @param groupIndex
     *            int 锟斤拷锟剿筹拷锟斤拷
     * @return Component[] 全锟斤拷锟斤拷员锟斤拷锟�
     */
    public Component[] getMembers(int groupIndex) {
        return getGroup(groupIndex).getMembers();
    }

    /**
     * 取锟矫筹拷员锟斤拷锟斤拷锟斤拷锟斤拷锟�
     *
     * @param groupIndex
     *            int 锟斤拷锟剿筹拷锟斤拷
     * @return int 锟斤拷锟斤拷
     */
    public int getMemberCount(int groupIndex) {
        return getGroup(groupIndex).getMemberCount();
    }

    /**
     * 取锟斤拷锟斤拷
     *
     * @param index
     *            int 锟斤拷锟剿筹拷锟斤拷
     * @return JGroupContainer 锟斤拷
     */
    protected JGroupContainer getGroup(int index) {
        return (JGroupContainer) groupList.get(index);
    }

    /**
     * 锟斤拷写锟斤拷addImpl锟斤拷锟斤拷,锟斤拷止锟斤拷锟斤拷JGroupPane锟斤拷锟斤拷锟斤拷锟斤拷
     *
     * @param comp
     *            Component
     * @param constraints
     *            Object
     * @param index
     *            int
     */
    protected void addImpl(Component comp, Object constraints, int index) {
        if (forbidFlag) {
            if (!(comp instanceof JGroupContainer)) {
                throw new UnsupportedOperationException(
                        "JGroupPane can't add component!");
            }
        } else {
            super.addImpl(comp, constraints, index);
        }
    }


    class GroupLayout implements LayoutManager, java.io.Serializable {
        int vgap = 0;

        int hgap = 0;

        public GroupLayout() {
        }

        public GroupLayout(int hg, int vg) {
            this.hgap = hg;
            this.vgap = vg;
        }

        public void addLayoutComponent(String name, Component comp) {
        }

        public void removeLayoutComponent(Component comp) {
        }

        public Dimension preferredLayoutSize(Container parent) {
            synchronized (parent.getTreeLock()) {
                Insets insets = parent.getInsets();
                int ncomponents = parent.getComponentCount();
                int w = 0;
                int h = 0;
                for (int i = 0; i < ncomponents; i++) {
                    Component comp = parent.getComponent(i);
                    Dimension d = comp.getPreferredSize();
                    if (w < d.width) {
                        w = d.width;
                    }
                    h += d.height + vgap;
                }
                return new Dimension(insets.left + insets.right + w + 2 * hgap,
                        insets.top + insets.bottom + h + 2 * vgap);
            }
        }

        public Dimension minimumLayoutSize(Container parent) {
            return preferredLayoutSize(parent);
        }

        public void layoutContainer(Container parent) {
            synchronized (parent.getTreeLock()) {
                Insets insets = parent.getInsets();
                int ncomponents = parent.getComponentCount();
                if (ncomponents == 0) {
                    return;
                }
                int y = insets.top + vgap;
                for (int c = 0; c < ncomponents; c++) {
                    int h = parent.getComponent(c).getPreferredSize().height;
                    parent.getComponent(c).setBounds(
                            insets.left + hgap,
                            y,
                            parent.getWidth() - insets.left - insets.right - 2
                                    * hgap, h);
                    y += h + vgap;
                }
            }
        }

        public String toString() {
            return getClass().getName();
        }
    }


    class JGroupContainer extends JPanel {
        private JButton bttGroupTitle = new JButton();

        private JPanel pMembers = new JPanel();

        // private JScrollPane sp;
        public JGroupContainer() {
            this("");
        }

        public JGroupContainer(String name) {
            this(name, UIManager.getColor("Desktop.background"));
        }

        /**
         * @param name
         *            String 锟斤拷锟斤拷
         * @param background
         *            Color 锟斤拷员锟斤拷锟斤拷锟斤拷锟斤拷锟藉背锟斤拷色
         */
        public JGroupContainer(String name, Color background) {
            bttGroupTitle.setText(name);
            bttGroupTitle.setFocusable(false);
            pMembers.setLayout(new GroupLayout(5, 5));
            this.setLayout(new BorderLayout());
            this.add(bttGroupTitle, BorderLayout.NORTH);

            // pMembers.setBackground(background);

            Color thumbColor = UIManager.getColor("ScrollBar.thumb");
            Color trackColor = UIManager.getColor("ScrollBar.track");
            Color trackHighlightColor = UIManager
                    .getColor("ScrollBar.trackHighlight");

            UIManager.put("ScrollBar.thumb", background);
            UIManager.put("ScrollBar.track", background);
            UIManager.put("ScrollBar.trackHighlight", background);
            /*
             * sp = new JScrollPane(pMembers); sp.setHorizontalScrollBarPolicy(
             * JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
             */
            this.add(pMembers, BorderLayout.CENTER);
            collapse();
            UIManager.put("ScrollBar.thumb", thumbColor);
            UIManager.put("ScrollBar.track", trackColor);
            UIManager.put("ScrollBar.trackHighlight", trackHighlightColor);

        }

        /**
         * 锟斤拷锟矫硷拷锟�
         *
         * @param hgap
         *            int 锟斤拷锟斤拷
         * @param vgap
         *            int 锟斤拷锟斤拷
         */
        public void setMemberGap(int hgap, int vgap) {
            pMembers.setLayout(new GroupLayout(hgap, vgap));
        }

        /**
         * 取锟斤拷锟斤拷谋锟斤拷獍磁�
         *
         * @return JButton
         */
        public JButton getTitleButton() {
            return bttGroupTitle;
        }

        /**
         * 取锟斤拷锟斤拷某锟皆憋拷锟斤拷锟斤拷锟�
         *
         * @return JPanel
         */
        public JPanel getMembersContainer() {
            return pMembers;
        }

        /**
         * 锟斤拷锟斤拷锟斤拷
         */
        public void collapse() {
            pMembers.setVisible(false);
            this.revalidate();
        }

        /**
         * 展锟斤拷锟斤拷
         */
        public void expand() {
            pMembers.setVisible(true);
            this.revalidate();
        }

        /**
         * 锟斤拷锟斤拷锟斤拷锟斤拷
         *
         * @param name
         *            String 锟斤拷锟斤拷
         */
        public void setName(String name) {
            bttGroupTitle.setText(name);
        }

        /**
         * 取锟斤拷锟斤拷锟斤拷
         *
         * @return String
         */
        public String getName() {
            return bttGroupTitle.getText();
        }

        /**
         * 锟斤拷锟揭伙拷锟斤拷员锟斤拷锟�
         *
         * @param index
         *            int 顺锟斤拷锟�
         * @param c
         *            Component 锟斤拷员锟斤拷锟�
         */
        public void addMember(int index, Component c) {
            pMembers.add(c, index);
            pMembers.doLayout();
        }

        /**
         * 删锟斤拷一锟斤拷锟皆憋拷锟斤拷
         *
         * @param index
         *            int 顺锟斤拷锟�
         */
        public void removeMember(int index) {
            pMembers.remove(index);
            pMembers.doLayout();
        }

        /**
         * 取锟斤拷一锟斤拷锟皆憋拷锟斤拷
         *
         * @param index
         *            int 顺锟斤拷锟
         * @return Component 锟斤拷员锟斤拷锟
         */
        public Component getMember(int index) {
            return pMembers.getComponent(index);
        }

        /**
         * 取锟斤拷全锟斤拷锟斤拷员锟斤拷锟
         *
         * @return Component[] 锟斤拷员锟斤拷锟
         */
        public Component[] getMembers() {
            Component coms[] = new Component[getMemberCount()];
            for (int i = 0; i < coms.length; i++) {
                coms[i] = pMembers.getComponent(i);
            }
            return coms;
        }

        /**
         * 取锟矫筹拷员锟斤拷锟斤拷锟斤拷锟
         *
         * @return int 锟斤拷锟斤拷
         */
        public int getMemberCount() {
            return pMembers.getComponentCount();
        }

        /**
         * 锟斤拷写锟斤拷toString锟斤拷锟斤拷
         *
         * @return String
         */
        public String toString() {
            return getName();
        }
    }
}

class AddFileUI extends JFrame {
	void run() {
		JButton JB = new JButton();
		JB.setText("Add");
		this.add(JB);
		this.setVisible(true);
		this.setBounds(400, 400, 200, 200);
	}
}